package com.turing.common.util;


import java.io.UnsupportedEncodingException;
import java.util.Base64;

/**
 * @author ：XiLuo
 * @date ：Created in 2019/6/3 15:42
 * @description：
 * @modified By：
 * @version: $
 */
public class Base64Utils {

    private static final Base64.Encoder encoder = Base64.getEncoder();

    private static final Base64.Decoder decoder = Base64.getDecoder();


    public static String encode(String text) {
        String encodedStr = null;
        try {
            encodedStr = encoder.encodeToString(text.getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return encodedStr;
    }


    public static String decode(String text) {
        String decodedStr = null;
        try {
            decodedStr = new String(decoder.decode(text), "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return decodedStr;
    }
}
